<?php 
Configure::write('LilcartPlugin.tablePrefix', '');
App::import('Model', 'Lilcart.Item');

class TestItem extends Item {
	var $cacheSources = false;
	var $useDbConfig  = 'test_suite';
}

class ItemTestCase extends CakeTestCase {
	var $Item = null;
	var $fixtures = array('plugin.lilcart.item', 'plugin.lilcart.category', 'plugin.lilcart.categories_item');

	function start() {
		parent::start();
		$this->Item = new TestItem();
	}

	function testItemInstance() {
		$this->assertTrue(is_a($this->Item, 'Item'));
	}

	function testItemFind() {
		$this->Item->recursive = -1;
		$results = $this->Item->find('first');
		$this->assertTrue(!empty($results));

		$expected = array('Item' => array(
			'id'  => 1,
			'slug'  => 'dell-latitude-d830',
			'title'  => 'Dell Lattitude D830',
			'descript'  => 'The D830 enhances the previous generation Latitude D820 with the latest 64-bit dual-core Intel processors and support for three different graphics solutions, all in one platform with a starting weight of less than six pounds.',
			'price_current'  => 1308.0,
			'price_original'  => 1420.0,
			'created'  => '2008-09-01 20:23:55',
			'modified'  => '2008-09-01 20:23:55'
		),);
		$this->assertEqual($results, $expected);
	}
	
	function testFetchForCategory() {
		// simple lookup - find all items manufactured by "HP"
		$expected = array(3);
		$data = $this->Item->fetchForCategory(11);
		$this->assertEqual(Set::Extract($data, '{n}.Item.id'), $expected);
		
		// looking for items in category "Workstations" manufactured by "Dell"
		$expected = array(2);
		$data = $this->Item->fetchForCategory(array(5, 10));
		$this->assertEqual(Set::Extract($data, '{n}.Item.id'), $expected);
		
		// looking for items in category "Computers" manufactured by "Dell"
		$expected = array(1, 2);
		$data = $this->Item->fetchForCategory(array(2, 10));
		$this->assertEqual(Set::Extract($data, '{n}.Item.id'), $expected);
	}
}
?>